import { baseUrlApi, requestClient, type Result } from '#/api/request';
// 用户数据类型
export interface UserData {
  user_login: string; // 用户名
  user_email: string; // 邮箱
  user_pass: string; // 密码
  role_ids: object; // 角色ids
  id?: number;
}

// 用户请求参数
interface UserParams {
  user_login?: string;
  user_email?: string;
}

/** 管理员列表 */
export const getAdminUsers = (params?: UserParams) => {
  return requestClient.get<Result>(baseUrlApi('/admin/users'), { params });
};

/**
 * 添加管理员
 * @param data
 * @returns
 */
export const postAdminUsers = (data?: UserData) => {
  return requestClient.post<Result>(baseUrlApi('/admin/users'), data);
};

/**
 * 获取管理员信息
 * @param id
 * @returns
 */
export const getAdminUsersInfo = (id: number) => {
  return requestClient.get<Result>(baseUrlApi(`/admin/users/${id}`));
};

/**
 * 编辑管理员
 * @param id
 * @param data
 * @returns
 */
export const putAdminUsers = (id: number, data: UserData) => {
  return requestClient.put<Result>(baseUrlApi(`/admin/users/${id}`), data);
};

/**
 * 删除管理员
 * @param id
 * @returns
 */
export const deleteAdminUsers = (id: number) => {
  return requestClient.delete<Result>(baseUrlApi(`/admin/users/${id}`));
};

/**
 * 设置管理员启用状态
 * @param id 管理员id
 * @param status 管理员显示状态,0:隐藏;1:显示
 * @returns
 */
export const postAdminUsersStatus = (id: number, status: number) => {
  return requestClient.post<Result>(
    baseUrlApi(`/admin/users/${id}/status/${status}`),
  );
};
